<template>
	<el-card>
		<el-form :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item>
				<fast-select v-model="state.queryForm.typeGroup" dict-type="contract_group" clearable placeholder="合同大类"></fast-select>
			</el-form-item>
			<el-form-item>
				<el-input v-model="state.queryForm.typeCode" placeholder="类型代码"></el-input>
			</el-form-item>
			<el-form-item>
				<el-input v-model="state.queryForm.typeName" placeholder="类型名称"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="success" @click="getDataList()">查询</el-button>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="addOrUpdateHandle()">新增</el-button>
			</el-form-item>
		</el-form>
		<el-table v-loading="state.dataListLoading" :data="state.dataList" row-key="id" border style="width: 100%">
			<fast-table-column prop="typeGroup" label="合同大类" dict-type="contract_group"></fast-table-column>
			<el-table-column prop="typeCode" label="类型代码" />
			<el-table-column prop="typeName" label="类型名称" />
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button size="small" type="primary" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
					<el-button size="small" type="danger" @click="deleteBatchHandle(scope.row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.page"
			:page-sizes="state.pageSizes"
			:page-size="state.limit"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>
		<add-or-update ref="addOrUpdateRef" @refresh-data-list="getDataList"></add-or-update>
	</el-card>
</template>

<script lang="ts" setup>
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import AddOrUpdate from './add-or-update.vue'
import { IHooksOptions } from '@/hooks/interface'
import { autoResetRef } from '@vueuse/core';

const state: IHooksOptions = reactive({
	dataListUrl: '/sys/contract/type/page',
	deleteUrl: '/sys/contract/type',
	queryForm: {
		typeGroup: '',
		typeCode: '',
		typeName: ''
	}
})

const addOrUpdateRef = ref()
const addOrUpdateHandle = (id?: Number) => {
	addOrUpdateRef.value.init(id)
}

const { getDataList, deleteHandle, selectionChangeHandle, sizeChangeHandle, currentChangeHandle, deleteBatchHandle } = useCrud(state)
</script>

<style></style>
